﻿<!--revision $Id$-->
<UserControl x:Class="OpenWPFChart.Helpers.ChooseColorDialog.ColorChooser"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:local="clr-namespace:OpenWPFChart.Helpers.ChooseColorDialog"
    Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"
	MinHeight="200" MinWidth="250">

	<UserControl.Resources>
		<Style x:Key="dialogButtonStyle" TargetType="Button">
			<Setter Property="Margin" Value="5"/>
			<Setter Property="Width" Value="75"/>
		</Style>
		<Style x:Key="dialogButtonPanelStyle">
			<Setter Property="FrameworkElement.Margin" Value="0,0,10,0"/>
			<Setter Property="FrameworkElement.HorizontalAlignment" Value="Right"/>
		</Style>

		<DrawingBrush x:Key="checkboardBrush" 
			Stretch="None" TileMode="Tile" AlignmentX="Left" AlignmentY="Top" 
			Viewport="0,0,10,10" ViewportUnits="Absolute">
			<DrawingBrush.Drawing>
				<DrawingGroup>
					<GeometryDrawing Brush="sc# 1,1,1">
						<GeometryDrawing.Geometry>
							<RectangleGeometry Rect="0,0,10,10" />
						</GeometryDrawing.Geometry>
					</GeometryDrawing>
					<GeometryDrawing Brush="sc# 0.5,0.5,0.5">
						<GeometryDrawing.Geometry>
							<RectangleGeometry Rect="0,0,5,5" />
						</GeometryDrawing.Geometry>
					</GeometryDrawing>
					<GeometryDrawing Brush="sc# 0.5,0.5,0.5">
						<GeometryDrawing.Geometry>
							<RectangleGeometry Rect="5,5,5,5" />
						</GeometryDrawing.Geometry>
					</GeometryDrawing>
				</DrawingGroup>
			</DrawingBrush.Drawing>
		</DrawingBrush>

		<BooleanToVisibilityConverter x:Key="boolToVisibility"/>
	</UserControl.Resources>

	<Grid Name="contentHost">
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto"/>
			<RowDefinition/>
		</Grid.RowDefinitions>
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="Auto"/>
			<ColumnDefinition/>
		</Grid.ColumnDefinitions>

		<!--Color Sample-->
		<Border HorizontalAlignment="Center"
				BorderBrush="Black" BorderThickness="1" Margin="5">
			<Grid Height="30" Width="50">
				<Rectangle Fill="{StaticResource checkboardBrush}"/>
				<Rectangle>
					<Rectangle.Fill>
						<SolidColorBrush Color="{Binding Path=SelectedColor}"/>
					</Rectangle.Fill>
				</Rectangle>
			</Grid>
		</Border>

		<!--Color Components-->
		<StackPanel Grid.Row="1" Margin="5">
			<StackPanel.Resources>
				<Style TargetType="{x:Type TextBlock}">
					<Setter Property="Margin" Value="3,0,3,0"/>
				</Style>

				<local:ColorToHSLConverter x:Key="colorToHSLConverter"/>
			</StackPanel.Resources>

			<Expander Header="ScRGB">
				<Grid DataContext="{Binding Path=SelectedColor}">
					<Grid.RowDefinitions>
						<RowDefinition Height="Auto"/>
						<RowDefinition Height="Auto"/>
						<RowDefinition Height="Auto"/>
						<RowDefinition Height="Auto"/>
					</Grid.RowDefinitions>
					<Grid.ColumnDefinitions>
						<ColumnDefinition />
						<ColumnDefinition />
					</Grid.ColumnDefinitions>

					<TextBlock Grid.Row="0">ScA</TextBlock>
					<TextBlock Grid.Row="0" Grid.Column="1" 
							Text="{Binding Path=ScA, StringFormat=F4}"/>
					<TextBlock Grid.Row="1">ScR</TextBlock>
					<TextBlock Grid.Row="1" Grid.Column="1" 
							Text="{Binding Path=ScR, StringFormat=F4}"/>
					<TextBlock Grid.Row="2">ScG</TextBlock>
					<TextBlock Grid.Row="2" Grid.Column="1" 
							Text="{Binding Path=ScG, StringFormat=F4}"/>
					<TextBlock Grid.Row="3">ScB</TextBlock>
					<TextBlock Grid.Row="3" Grid.Column="1" 
							Text="{Binding Path=ScB, StringFormat=F4}"/>
				</Grid>
			</Expander>
			<Rectangle Height="5" Fill="DarkSlateGray"/>
			<Expander Header="RGB" IsExpanded="True">
				<Grid DataContext="{Binding Path=SelectedColor}">
					<Grid.RowDefinitions>
						<RowDefinition Height="Auto"/>
						<RowDefinition Height="Auto"/>
						<RowDefinition Height="Auto"/>
						<RowDefinition Height="Auto"/>
					</Grid.RowDefinitions>
					<Grid.ColumnDefinitions>
						<ColumnDefinition />
						<ColumnDefinition />
					</Grid.ColumnDefinitions>

					<TextBlock Grid.Row="0">A</TextBlock>
					<TextBlock Grid.Row="0" Grid.Column="1" 
							Text="{Binding Path=A}"/>
					<TextBlock Grid.Row="1">R</TextBlock>
					<TextBlock Grid.Row="1" Grid.Column="1" 
							Text="{Binding Path=R}"/>
					<TextBlock Grid.Row="2">G</TextBlock>
					<TextBlock Grid.Row="2" Grid.Column="1" 
							Text="{Binding Path=G}"/>
					<TextBlock Grid.Row="3">B</TextBlock>
					<TextBlock Grid.Row="3" Grid.Column="1" 
							Text="{Binding Path=B}"/>
				</Grid>
			</Expander>
			<Rectangle Height="5" Fill="DarkSlateGray"/>
			<Expander Header="HSL" IsExpanded="True">
				<Grid DataContext="{Binding Path=SelectedColor,
						Converter={StaticResource colorToHSLConverter}}">
					<Grid.RowDefinitions>
						<RowDefinition Height="Auto"/>
						<RowDefinition Height="Auto"/>
						<RowDefinition Height="Auto"/>
						<RowDefinition Height="Auto"/>
					</Grid.RowDefinitions>
					<Grid.ColumnDefinitions>
						<ColumnDefinition />
						<ColumnDefinition />
					</Grid.ColumnDefinitions>

					<TextBlock Grid.Row="0">A</TextBlock>
					<TextBlock Grid.Row="0" Grid.Column="1" 
						Text="{Binding Path=Alpha, StringFormat=F3}"/>
					<TextBlock Grid.Row="1">H</TextBlock>
					<TextBlock Grid.Row="1" Grid.Column="1" 
						Text="{Binding Path=Hue, StringFormat=F2}"/>
					<TextBlock Grid.Row="2">S</TextBlock>
					<TextBlock Grid.Row="2" Grid.Column="1" 
						Text="{Binding Path=Saturation, StringFormat=F3}"/>
					<TextBlock Grid.Row="3">L</TextBlock>
					<TextBlock Grid.Row="3" Grid.Column="1" 
						Text="{Binding Path=Luminance, StringFormat=F3}"/>
				</Grid>
			</Expander>
		</StackPanel>

		<!--Color Pickers-->
		<Grid Grid.Column="1" Grid.RowSpan="2">
			<Grid.RowDefinitions>
				<RowDefinition/>
				<RowDefinition Height="Auto"/>
				<RowDefinition Height="Auto"/>
			</Grid.RowDefinitions>
			<Grid.ColumnDefinitions>
				<ColumnDefinition/>
				<ColumnDefinition/>
			</Grid.ColumnDefinitions>
			
			<local:KnownColorPicker 
					SelectedColor="{Binding Path=OpaqueColor}"
					Padding="5, 0, 5, 0"/>
			
			<CheckBox Grid.Row="1" Margin="5" 
					  IsChecked="{Binding Path=IsColorPickerVisible}">
				Show Color Picker
			</CheckBox>

			<local:RainbowColorPicker Grid.Column="1" MinWidth="250"
					SelectedColor="{Binding Path=OpaqueColor}"
					Visibility="{Binding Path=IsColorPickerVisible,
						Converter={StaticResource boolToVisibility}}"
					Margin="0,3,0,0" Padding="5, 0, 5, 0"
					BorderBrush="DarkGray" BorderThickness="1"
				/>

			<!--Opacity Slider-->
			<local:OpacitySlider Grid.Row="2" Grid.ColumnSpan="2"
				 SelectedOpacity="{Binding Path=Opacity}"
				 Height="28" Margin="5, 5, 3, 0"
				 BorderBrush="DarkGray" BorderThickness="1"/>
		</Grid>
	</Grid>
</UserControl>
